﻿# coding:utf-8
import urllib2 
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
from bs4 import BeautifulSoup

sys.setdefaultencoding("utf-8")
# 抓取分类的URL
url = 'http://www.wandoujia.com/category/game'
headers = {
	'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0',
	'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
	'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
	'Referer': 'http://www.wandoujia.com/app'
}
request = urllib2.Request(url, headers = headers)

response = urllib2.urlopen(request)
content = response.read().decode('utf-8')

soup = BeautifulSoup(content,'html.parser',from_encoding='utf-8')
ul = soup.find('ul',class_='clearfix tag-box')
alist = ul.find_all('a',class_='cate-link')

f = open('game_urls.txt','w')
count = 0;
for a in alist:
	f.write('%s -- %s \n' %(a['title'].encode('utf-8'),a['href']))

f.close()



